﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Data.Entity;

namespace verk2013_project_group12.Models
{
    public class AppDataContext : DbContext
    {
        public DbSet<Game> Games { get; set; }
        public DbSet<NewsItem> NewsItems { get; set; }
        public DbSet<FAQ> FAQs { get; set; }
        public DbSet<GameInstance> GameInstances { get; set; }
        public DbSet Membership { get; set; }
        public DbSet Roles { get; set; }
        public DbSet OAuthMembership { get; set; }
        public DbSet <UserProfile> UserProfiles { get; set; }
        public DbSet<GameRegistration> GameRegistrations { get; set; }
        public DbSet<GameInvite> GameInvites { get; set; }
        // Skoða þetta betur, þarf að specifya ON DELETE NO ACTION eða ON UPDATE NO ACTION
        // ON DELETE CASCADE ON UPDATE DO NOTHING ??

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Membership>()
                .HasMany<Role>(r => r.Roles)
                .WithMany(u => u.Members)
                .Map(m =>
                {
                    m.ToTable("webpages_UsersInRoles");
                    m.MapLeftKey("UserId");
                    m.MapRightKey("RoleId");
                });
        }
    }
}